//
// Created by Asus on 2025/5/31.
//

#include <iostream>
#include <memory>
#include <string>
using namespace std;

struct student {
    string name;
    int age;
    int score;
} stu3;

// c++风格
student stu4;

// c风格
struct student stu5;

typedef struct student2 {
    string name;
    int age;
    int score;
} stueft;

using stu = student;

typedef student stu2;


void demo01() {
    student stu1 = {};
    stu1.name = "John";
    stu1.age = 18;
    stu1.score = 20;
}

struct Student {
    //成员列表
    string name;  //姓名
    int age;      //年龄
    int score;    //分数
};

void demo02() {
    Student arr[3] = {
        {"张三",18,80 },
        {"李四",19,60 },
        {"王五",20,70 }
    };

    for (int i = 0; i < 3; i++)
    {
        cout << "姓名：" << arr[i].name << " 年龄：" << arr[i].age << " 分数：" << arr[i].score << endl;
    }
}

void demo03() {
    Student student;
    student.name = "John";
    student.age = 18;
    student.score = 20;
    Student *p = &student;
    cout << "姓名：" << p->name << " 年龄：" << p->age << " 分数：" << p->score << endl;
}


//教师结构体定义
struct Teacher
{
    //成员列表
    int id; //职工编号
    string name;  //教师姓名
    int age;   //教师年龄
    Student stu; //子结构体 学生
};

void demo04() {
    Teacher teacher;
    teacher.id = 10;
    teacher.name = "John";
    teacher.age = 18;
    teacher.stu.name = "John";
    teacher.stu.score = 20;
    teacher.stu.age = 18;

    cout << "教师 职工编号： " << teacher.id << " 姓名： " << teacher.name << " 年龄： " << teacher.age << endl;
    cout << "辅导学员 姓名： " << teacher.stu.name << " 年龄：" << teacher.stu.age << " 考试分数： " << teacher.stu.score << endl;
}

void printStudent(Student stu) {
    stu.age = 28;
    cout << "子函数中 姓名：" << stu.name << " 年龄： " << stu.age  << " 分数：" << stu.score << endl;
}

void printStudent2(Student *stu) {
    stu->age = 28;
    cout << "子函数中 姓名：" << stu->name << " 年龄： " << stu->age  << " 分数：" << stu->score << endl;
}

void demo05() {
    int a = 10;
    short b = short(a);
    short b2 = (short)a;
    // Student stu = { "张三",18,100};
    Student stu = { "张三",18,100};
    Student* s2 = reinterpret_cast<Student*>(&stu);  // 极端危险！
    Student* s3 = static_cast<Student*>(&stu);  // 极端危险！
    Student stu2 =  (Student)stu;
    //值传递
    printStudent(stu2);
    cout << "主函数中 姓名：" << stu.name << " 年龄： " << stu.age << " 分数：" << stu.score << endl;
    cout << endl;

    //地址传递
    printStudent2(&stu2);
    cout << "主函数中 姓名：" << stu.name << " 年龄： " << stu.age  << " 分数：" << stu.score << endl;
}

void printStudent3(const Student *stu) {
    //stu->age = 100; //操作失败，因为加了const修饰
    cout << "姓名：" << stu->name << " 年龄：" << stu->age << " 分数：" << stu->score << endl;
}

void printStudent3(const Student stu) {
    cout << "姓名：" << stu.name << " 年龄：" << stu.age << " 分数：" << stu.score << endl;
}


void process(const shared_ptr< Student> stu) {
    if (stu) {  // 等价于!stu->empty()
        // 使用stu->name
    }
}

void process(const shared_ptr< Student*> stu) {
    if (stu) {  // 等价于!stu->empty()
        // 使用stu->name
    }
}

void process(const shared_ptr<const Student*> stu) {
    if (stu) {  // 等价于!stu->empty()
        // 使用stu->name
    }
}

void process(const shared_ptr<const Student> stu) {
    if (stu) {  // 等价于!stu->empty()
        // 使用stu->name
    }
}

void demo06() {
    Student stu = { "张三",18,100 };
    printStudent3(&stu);
    printStudent3(stu);
}

int main(char *argv[]) {
    // demo01();
    // demo02();
    // demo03();
    // demo04();
    // demo05();
    demo06();
    return 0;
}
